<?php

/**
 * default actions.
 *
 * @package    vmdai
 * @subpackage default
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class toolsActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
    public function executeCalculator(sfWebRequest $request){
        //duration 天1月2
        //countdate 期限
        //yearrate利率
        //本金investmentamount
        //repayment还款方式
        
        $this->all = '0.00';
        $this->interest = '0.00';
        $this->investmentamount = "";
        $this->yearrate = "";
        $this->countdate = "";
        $this->duration = 2;
        if( $request->isMethod("POST") ) {
            $day = 1;
            $this->investmentamount = $request->getParameter("investmentamount", "");
            $this->yearrate = $request->getParameter("yearrate", 0);
            $this->duration = $request->getParameter("duration", 2);
            $this->countdate = $request->getParameter("countdate", "");
            
//            利息=(投资额*利率/360)*天
//利息=(投资额*利率/12)*月

            
            $rate = bcdiv($this->yearrate,100,sfConfig::get('app_value_bit'));
            if($this->duration == 1) {
		$money = bcmul($this->investmentamount,$rate,sfConfig::get('app_value_bit'));
		$accrual = bcdiv($money,360,sfConfig::get('app_value_bit'));
		$interest = bcmul($accrual,$this->countdate,sfConfig::get('app_value_bit'));
//                $interest = round($this->investmentamount /360*$this->countdate,2);
            }else{
		$money = bcmul($this->investmentamount,$rate,sfConfig::get('app_value_bit'));
		$accrual = bcdiv($money,12,sfConfig::get('app_value_bit'));
		$interest = bcmul($accrual,$this->countdate,sfConfig::get('app_value_bit'));
            }

            $this->all = $interest+$this->investmentamoun;
            $this->interest =$interest;
        }
    }
    
    public function executeIndex(sfWebRequest $request){

    }
}
